<?php
// backlinks
// position in google.com, google.be, google.nl
// pagerank


	
	
function backLink($input_url) {
  $api_service_url = "http://search.yahooapis.com/SiteExplorerService/V1/inlinkData";
  $apiid = "Dael8QvV34E5HD4MHVphcATqBtOoR6mvbF8weAAOYHlYyHcsJPxUc75M34jMlS08tchR";
  $query = $input_url;
  $entire_site  = "";
  $omit_inlinks = "domain";
  $linksperrequest = 100;
  $startposition = 1;
  $request_url = $api_service_url."?appid=".$apiid."&query=".urlencode($query)."&entire_site=".$entire_site."&omit_inlinks=".$omit_inlinks."&output=php";
  $currentpos = 0;
  while ($currentpos++ >= 0) {
      $requrl = sprintf("%s&start=%s&results=%s", $request_url, ($currentpos-1)*$linksperrequest+$startposition, $linksperrequest);
      if (($content = file_get_contents($requrl)) === FALSE ) {
          echo "HTTP error: $requrl";
          exit;
      } else {
          $data = unserialize($content);
          if (array_key_exists("ResultSet", $data)) {
              for ($i=0; $i<sizeof($data["ResultSet"]["Result"]); $i++) {
                $url = $data["ResultSet"]["Result"][$i]["Url"];
                $title = $data["ResultSet"]["Result"][$i]["Title"];
                $domain = 'http://'.parse_url($url, PHP_URL_HOST);
                $backlinks[$domain][] = array($url, $title);
              }
          } else {
              echo "Error: Bad response from server";
          }
           if (sizeof($data["ResultSet"]["Result"]) < $linksperrequest) break;
      }
  }
  define('BACKLINK_LIMIT',2);
  define('BACKLINK_TRUNCATE',1);
  define('BACKLINK_ALL',0);

  foreach ($backlinks as $domain => $links) {
      if (count($links) > BACKLINK_LIMIT) $backlinks[$domain] = array_slice($links, 0, BACKLINK_TRUNCATE);
  }

  sort($backlinks[$domain]);

  function print_backlinks($domain, $links, $num) {
      $limit = $num ? min($num,count($links)) : count($links);
      for ($i=0; $i < $limit; $i++) {
          list($url,$title) = $links[$i];
          echo '<li><a href="'.$url.'">'.$title.'</a></li>';
      }
  }
  echo '<ul>';

  foreach ($backlinks as $domain => $links) {
      if (count($links) > BACKLINK_LIMIT) {
          print_backlinks($domain, $links, BACKLINK_TRUNCATE);
      } else {
          print_backlinks($domain, $links, BACKLINK_ALL);
      }
  }
}

function placeInGoogle($url,$keyword,$domain,$lan="#h1nl",){

    $googleurl = "http://www.google.";
    $googledomain = $domain;
    $source = "hp";
    $query = "&q=".$keyword;
    $resultsperpage = "&num="20
    $blabla = "&aq=f&aqi=g10&aql=&oq=&gs_rfai=&fp=8637268cbe536c3e";
   #hl=en&source=hp&q=vectorworks&aq=f&aqi=g10&aql=&oq=&gs_rfai=&pbx=1&fp=7db4f7af4a13aa89

}
backLink('http://www.westworld.be/');
	
?>